package com.szsh.aiot.hsm.controller;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.szsh.aiot.common.annotation.CustomPermission;
import com.szsh.aiot.common.annotation.Log;
import com.szsh.aiot.common.core.domain.AjaxResult;
import com.szsh.aiot.common.core.domain.RequestDto;
import com.szsh.aiot.common.enums.BusinessType;
import com.szsh.aiot.hsm.dto.gateway.GatewayInfo;
import com.szsh.aiot.hsm.thirdService.GatewayInfoQueryClient;
import com.szsh.aiot.hsm.utils.PermitValidUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Des:网关信息查询接口
 * @Date 2024/3/25: 8:50
 */


@Controller
@RequestMapping("/gataway/info")
public class GateWayInfoController {

    private static final Logger LOGGER = LoggerFactory.getLogger(GateWayInfoController.class);

    @Autowired
    private PermitValidUtil permitValidUtil;

    @Autowired
    private GatewayInfoQueryClient gatewayInfoQueryClient;


    /**
     * 根据宽带号获取网关信息
     *
     * @param requestDto 请求参数
     * @return 处理结果
     */
    @RequestMapping(value = "/search/queryGatewayByBroadBand")
    @Log(title = "获取网关mac信息", businessType = BusinessType.OTHER)
    @CustomPermission
    @ResponseBody
    public AjaxResult cameraAccessReminder(@RequestBody RequestDto requestDto) {

        String sequenceNo = requestDto.getSequenceNo();
        LOGGER.info("请求参数为{},sequenceNo={}", requestDto.getRequestJsonElement(), sequenceNo);
        JsonObject requestParams = requestDto.getRequestJsonElement().getAsJsonObject();
        String broadbandNO = permitValidUtil.getElementValue(requestParams, "broadbandNO");
        GatewayInfo gatewayInfo = gatewayInfoQueryClient.queryByPPOE(broadbandNO);
        if (gatewayInfo != null) {
            LOGGER.info("data{}",new Gson().toJson(gatewayInfo).toString());
             return new AjaxResult(AjaxResult.Type.SUCCESS,"查询成功",gatewayInfo);
        }
        return AjaxResult.error("未查询到相关数据");
    }
}
